home *** CD-ROM | disk | FTP | other *** search
- #define CURSES_LIBRARY 1
- #include <curses.h>
-
- #ifdef PDCDEBUG
- char *rcsid__chadd = "$Header: C:\CURSES\private\RCS\_chadd.c 2.1 1993/06/18 20:22:37 MH Rel MH $";
- #endif
-
-
-
-
- /*man-start*********************************************************************
-
- PDC_chadd() - Low level; Put a character to a window
-
- PDCurses Description:
- This is a private PDCurses function.
-
- This routine will insert the character 'c' at the current cursor
- position in the passed window.
-
- If 'xlat' is TRUE, PDC_chadd() will handle things in a cooked
- manner (tabs, newlines, carriage returns, etc). If 'xlat' is
- FALSE, the characters are simply output directly.
-
- If 'advance' is TRUE, PDC_chadd() will move the current cusor position
- appropriately. The *addch functions call PDC_chadd() with advance TRUE,
- while the *insch functions call PDC_chadd() with advance FALSE.
-
- The normal curses routines (non-raw-output-mode) call PDC_chadd()
- with 'xlat' TRUE.
-
- PDCurses Return Value:
- This function returns OK on success and ERR on error.
-
- PDCurses Errors:
- It is an error to call this function with a NULL window pointer.
-
- Portability:
- PDCurses int PDC_chadd( WINDOW* win, chtype ch, bool xlat, bool advance );
-
- **man-end**********************************************************************/
-
- int PDC_chadd(register WINDOW *win, chtype ch,bool xlat, bool advance)
- {
- int retval = ERR;
- int x;
- int y;
- int newx;
- chtype attr;
- int ts;
-
- #ifdef PDCDEBUG
- if (trace_on) PDC_debug("PDC_chadd() - called: char=%c attr=0x%x xlat=%d advance=%d\n",ch & A_CHARTEXT,ch & A_ATTRIBUTES,xlat,advance);
- #endif
-
- if (win == (WINDOW *)NULL)
- return( retval );
-
- x = win->_curx;
- y = win->_cury;
- ts = win->_tabsize;
-
- /* if the incoming character doesn't have its own attribute
- then use the current attributes for the window.
- if the incoming character has attributes but not a colour
- component, or the attributes to the current attributes
- for the window.
- if the incoming character has a colour component use the
- attributes solely from the incoming character */
-
- if ((ch & A_ATTRIBUTES) == 0)
- attr = win->_attrs;
- else
- if ((ch & A_COLOR) == 0)
- attr = (ch & A_ATTRIBUTES) | win->_attrs;
- else
- attr = (ch & A_ATTRIBUTES);
-
- ch = (ch & A_CHARTEXT);
-
- if ((y > win->_maxy) ||
- (x > win->_maxx) ||
- (y < 0) ||
- (x < 0))
- {
- return( retval );
- }
-
- if (xlat)
- {
- switch (ch) {
- case '\t':
- for (newx = ((x / ts) + 1) * ts; x < newx; x++)
- {
- if (waddch(win, ' ') == ERR)
- {
- return( retval );
- }
- /*
- * if tab to next line
- */
- if (win->_curx == 0)
- {
- /*
- * exit the loop
- */
- return( OK );
- }
- }
- return( OK );
-
- case '\n':
- if (_cursvar.autocr && !(_cursvar.raw_out))
- {
- /*
- * if lf -> crlf
- */
- x = 0;
- }
- wclrtoeol( win );
- if ((y = PDC_newline(win, y)) < 0)
- return( retval );
- if (advance)
- {
- win->_cury = y;
- win->_curx = x;
- }
- return( OK );
-
- case '\r':
- if (advance)
- win->_curx = x = 0;
- return( OK );
-
- case '\b':
- if (--x < 0) /* back over left margin ? */
- {
- if (--y < 0) /* already at upper left ! */
- {
- x = 0;
- y = 0;
- }
- else x = win->_maxx - 1;
- }
- if (advance)
- {
- win->_cury = y;
- win->_curx = x;
- }
- return( OK );
-
- case 0x7f:
- if (waddch(win, '^') == ERR)
- {
- return( retval );
- }
- retval = waddch(win, '?');
- return( retval );
-
- default:
- break;
- } /* switch */
-
- if (ch < ' ')
- {
- /*
- * handle control chars
- */
- if (waddch(win, '^') == ERR)
- return( retval );
-
- retval = (waddch(win, ch + '@'));
- return( retval );
- }
- }
-
- /*
- * Add the attribute back into the character.
- */
- ch |= attr;
- /*********************************************************************/
- /* only change _firstch/_lastch if character to be added is different */
- /* to the character/attribute that is already in that position in the */
- /* window. */
- /* Removing this fixes display problems with different windows in the */
- /* same physical position. MH 20-03-93 */
- /* Restored again. MH 02-04-93 */
- /*********************************************************************/
- if (win->_y[y][x] != ch)
- {
- /*
- * only if data change
- */
- if (win->_firstch[y] == _NO_CHANGE)
- {
- win->_firstch[y] = win->_lastch[y] = x;
- }
- else
- {
- if (x < win->_firstch[y])
- {
- win->_firstch[y] = x;
- }
- else
- {
- if (x > win->_lastch[y])
- {
- win->_lastch[y] = x;
- }
- }
- }
- }
- win->_y[y][x++] = ch;
- if (x >= win->_maxx)
- {
- /*
- * wrap around test
- */
- x = 0;
- if ((y = PDC_newline(win, y)) < 0)
- return( retval );
- }
- if (advance)
- {
- win->_curx = x;
- win->_cury = y;
- }
- return( OK );
- }
-